package org.liveboardgames.agricola.control.delegates.action.prerequisite
{
    import org.liveboardgames.agricola.control.delegates.helper.GameHelper;
    import org.liveboardgames.agricola.model.enums.ResourceTypeEnum;
    import org.liveboardgames.agricola.vo.player.Player;
    import org.liveboardgames.common.dictionary.collections.IMap;
    
    import mx.collections.ListCollectionView;
    
    public class OvenPrerequisiteChecker extends PrerequisiteChecker
    {
        public function OvenPrerequisiteChecker(player:Player)
        {
            super(player);
        }
        
        override public function check():Boolean
        {
            var result:Boolean = true;
            
            // Check that the player has an Oven
            var ovens:ListCollectionView = GameHelper.getOvens(player.farm);
            if (ovens == null || ovens.length == 0)
            {
                result = false;
            }
            // Check that the player has at least one grain to bake
            else
            {
                var resources:IMap = player.farm.resources;
                if (resources == null || resources.getValue(ResourceTypeEnum.GRAIN) == 0)
                {
                    result = false;
                }
            }
            
            return result;
        }
    }
}